home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / QD3D to QTVR / ArticleCode / Source / panoCamera.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  3.9 KB  |  127 lines  |  [TEXT/MPCC]

  1. #include <FixMath.h>
  2. #include "QD3DtoQTVR.h"
  3. #include "extern.h"
  4. #include "camera.h"
  5.  
  6. TQ3CameraObject MyNewCamera(CWindowPtr theWindow)
  7. {
  8.     TQ3ViewAngleAspectCameraData    perspectiveData;
  9.     TQ3CameraObject                    camera;
  10.     // Set the field of view to 74 degrees (or 74*kQ3Pi/180 radians).
  11.     float                             fieldOfView =  74.0*kQ3Pi/180.0;
  12.     TQ3Status                        returnVal = kQ3Failure ;
  13.  
  14.     // Assign default placement and range
  15.     perspectiveData.cameraData.placement.cameraLocation     = kMyDefaultFrom;
  16.     perspectiveData.cameraData.placement.pointOfInterest     = kMyDefaultTo;
  17.     perspectiveData.cameraData.placement.upVector             = kMyDefaultUp;
  18.     perspectiveData.cameraData.range.hither    = kMyDefaultHither;
  19.     perspectiveData.cameraData.range.yon     = kMyDefaultYon;
  20.  
  21.     // Assign standard viewport
  22.     perspectiveData.cameraData.viewPort.origin.x = -1.0;
  23.     perspectiveData.cameraData.viewPort.origin.y = 1.0;
  24.     perspectiveData.cameraData.viewPort.width = 2.0;
  25.     perspectiveData.cameraData.viewPort.height = 2.0;
  26.     
  27.     perspectiveData.fov                = fieldOfView;
  28.     perspectiveData.aspectRatioXToY    =
  29.         (float) (theWindow->portRect.right - theWindow->portRect.left) / 
  30.         (float) (theWindow->portRect.bottom - theWindow->portRect.top);
  31.         
  32.     camera = Q3ViewAngleAspectCamera_New(&perspectiveData);
  33.     
  34.     return camera ;
  35. }
  36.  
  37. void MyGetBoundingSphere(TQ3ViewObject viewObject, TQ3GroupObject mainGroup,
  38.                      TQ3BoundingSphere *viewBSphere)
  39. {
  40.     TQ3Status                    status;
  41.     
  42.     Q3View_StartBoundingSphere(viewObject,kQ3ComputeBoundsApproximate);
  43.     do {
  44.         status = Q3DisplayGroup_Submit(mainGroup, viewObject);
  45.     } while (Q3View_EndBoundingSphere(viewObject, viewBSphere) == kQ3ViewStatusRetraverse);                                        
  46. }
  47.  
  48. void MyInitPanoCamera(DocumentPtr theDocument)
  49. {
  50.     TQ3BoundingSphere             viewBSphere;
  51.     float                        viewRadius;
  52.     TQ3Point3D                    zeroPoint    = {0,0,0};
  53.     
  54.     if(theDocument == NULL)
  55.         return;
  56.         
  57.     // Get the bounding sphere of the drawable group (the entire model) in the view.
  58.     MyGetBoundingSphere(theDocument->theView, theDocument->documentGroup, &viewBSphere);
  59.  
  60.     // Get the bounding sphere's center and radius
  61.     theDocument->documentGroupCenter = viewBSphere.origin;
  62.     viewRadius = viewBSphere.radius;
  63.     
  64.     // Center the camera.
  65.     MyPlaceCamera(theDocument, theDocument->documentGroupCenter.x,
  66.                 theDocument->documentGroupCenter.y,
  67.                 theDocument->documentGroupCenter.z,
  68.                 theDocument->documentGroupCenter.x,
  69.                 theDocument->documentGroupCenter.y,
  70.                 theDocument->documentGroupCenter.z+1.0);
  71. }
  72.  
  73.  
  74. void    MyRotateCameraY(DocumentPtr theDocument, float dY)
  75. {
  76.     TQ3CameraObject        camera;
  77.     TQ3CameraPlacement    cameraPos;
  78.     TQ3Matrix4x4        myRotation;
  79.     TQ3Vector3D            initialVector,rotatedVector;
  80.     
  81.     Q3View_GetCamera(theDocument->theView, &camera );
  82.     Q3Camera_GetPlacement(camera, &cameraPos);
  83.     
  84.     // Get Z Vector
  85.     Q3Point3D_Subtract(&cameraPos.pointOfInterest,&cameraPos.cameraLocation,&initialVector);
  86.     
  87.     // Get rotation about Y axis.
  88.     Q3Matrix4x4_SetRotateAboutAxis(&myRotation,&cameraPos.cameraLocation,&cameraPos.upVector,dY);
  89.     
  90.     // Rotate Z vector about Y axis.
  91.     Q3Vector3D_Transform(&initialVector,&myRotation,&rotatedVector);
  92.     
  93.     // Get Point of Interest from Rotated vector. The upVector does not change.
  94.     Q3Point3D_Vector3D_Add(&cameraPos.cameraLocation,&rotatedVector,&cameraPos.pointOfInterest);
  95.     
  96.     Q3Camera_SetPlacement(camera, &cameraPos);
  97.     Q3View_SetCamera(theDocument->theView, camera );
  98.     Q3Object_Dispose(camera);
  99. }
  100.  
  101.  
  102. void    MyPlaceCamera(DocumentPtr theDocument, float fromX,float fromY,float fromZ,
  103.                 float toX,float toY,float toZ)
  104. {
  105.     TQ3CameraObject        camera;
  106.     TQ3CameraPlacement    cameraPos;
  107.  
  108.     Q3View_GetCamera(theDocument->theView, &camera );
  109.     Q3Camera_GetPlacement(camera, &cameraPos);
  110.     
  111.     cameraPos.cameraLocation.x = fromX;
  112.     cameraPos.cameraLocation.y = fromY;
  113.     cameraPos.cameraLocation.z = fromZ;
  114.     
  115.     cameraPos.pointOfInterest.x = toX;
  116.     cameraPos.pointOfInterest.y = toY;
  117.     cameraPos.pointOfInterest.z = toZ;
  118.     
  119.     Q3Camera_SetPlacement(camera, &cameraPos);
  120.     Q3View_SetCamera(theDocument->theView, camera );
  121.     Q3Object_Dispose(camera);
  122. }
  123.  
  124.  
  125.  
  126.  
  127.